package com.vzaar.examples;

import com.vzaar.User;
import com.vzaar.Vzaar;
import com.vzaar.VzaarException;

/**
 * Example of getting user details.
 * 
 * @author Marc G. Smith
 */
public class UserDetailsExample 
{
	///////////////////////////////////////////////////////////////////////////

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			ParameterHelper helper = new ParameterHelper(args);
			args = helper.getRemainingArgs();
			if(args.length != 1) {
				printUsage();
				System.exit(1);
				return;
			}

			Vzaar vzaar = helper.createVzaar();
			User user = vzaar.getUserDetails(args[0]);
			System.out.println("Author Name:    " + user.getAuthorName());
			System.out.println("Author Id:      " + user.getAuthorId());
			System.out.println("Author Url:     " + user.getAuthorUrl());
			System.out.println("Author Account: " + user.getAuthorAccount());
			System.out.println("Created At:     " + user.getCreatedAt());
			System.out.println("Video Count:    " + user.getVideoCount());
			System.out.println("Play Count:     " + user.getPlayCount());
		}
		catch(VzaarException e) {
			System.err.println("Error: " + e.getMessage());
			System.exit(2);
		}
		catch(ArrayIndexOutOfBoundsException e) {
			printUsage();
			System.exit(1);
		}
	}
	
	///////////////////////////////////////////////////////////////////////////

	private static final  void printUsage() {
		System.out.println("Usage: vzaar-user " +
			ParameterHelper.getCommonCommandLineArgs() + " <username>\n");
		System.out.println("Params:");
		System.out.println("   <username>          " +
			"The username to query");
		System.out.println(ParameterHelper.getCommonCommandLineHelp());
	}

	///////////////////////////////////////////////////////////////////////////
}
